<?php
class I18n{
	var $aMsg;
	var $sIdLang;
	
	function I18n(){
		$aMsg = "";
		$sIdLang = "";
	}
    
    function strToHex($string)
    {
        $hex='';
        for ($i=0; $i < strlen($string); $i++)
            $hex .= dechex(ord($string[$i]));
            
        return $hex;
    }

    function hexToStr($hex)
    {
        $string='';
        for ($i=0; $i < strlen($hex)-1; $i+=2)
        {
            $string .= chr(hexdec($hex[$i].$hex[$i+1]));
        }
        return $string;
    }

    function rmBOM($string) {
		$strHex = bin2hex($string);
		$newStr = str_replace("efbbbf", "", $strHex);
		$strHex = str_replace("0d0a", "", $newStr);
        $string = $this->hexToStr($strHex);
        return $string;     
    }
    
    function my_parse_ini($sFileName){

        $newA = array();
        $a = file ($sFileName);
        foreach ($a as $line){
            list($tmpkey, $value) = explode("=", $line, 2);
            $key = $this->rmBOM($tmpkey);
            $newA[$key] = $this->rmBOM($value);
        }
        return($newA);
    }
	
	function setIdLang($sIdLang){
	   $this->sIdLang = $sIdLang;
	}
	
	function setMsg($sFilePath){
		$this->aMsg = $this->my_parse_ini($sFilePath);
	}
	
	function getResourceString($sIdMsg){
		return($this->aMsg[$sIdMsg]);
	}
       	
}	 
?>
